using System;
using Godot;

namespace Arcane.Source;

public enum Element : byte
{
    Cryo,
    Pyro,
    Electro,
    Matter,
    Arcane,
    Techno,
    Size,
}

public static class ElementExt
{
    public readonly static Element[] ELEMENTS = 
    [
        Element.Cryo,
        Element.Pyro,
        Element.Electro,
        Element.Matter,
        Element.Arcane,
        Element.Techno
    ];

    public static int AsInt(this Element type) => (int)type;

    public static Element? ParseElement(this string id)
    {
        return id switch
        {
            "cryo" => Element.Cryo,
            "pyro" => Element.Pyro,
            "electro" => Element.Electro,
            "matter" => Element.Matter,
            "arcane" => Element.Arcane,
            "techno" => Element.Techno,
            _ => null,
        };
    }

    public static Element? ParseElement(this StringName id)
    {
        if (id == StringNames.CRYO)
        {
            return Element.Cryo;
        }

        if (id == StringNames.PYRO)
        {
            return Element.Pyro;
        }

        if (id == StringNames.ELECTRO)
        {
            return Element.Electro;
        }

        if (id == StringNames.MATTER)
        {
            return Element.Matter;
        }

        if (id == StringNames.ARCANE)
        {
            return Element.Arcane;
        }

        if (id == StringNames.TECHNO)
        {
            return Element.Techno;
        }

        return null;
    }

    public static Element PickRandom(RandomNumberGenerator rng)
    {
        return ELEMENTS[rng.RandiRange(0, ELEMENTS.Length - 1)];
    }

    internal static Element PickRandom(object rng)
    {
        throw new NotImplementedException();
    }
}